<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use DB;
use App\Repos\OrderRepo;
use App\Repos\OrderGroupRepo;
use App\Repos\ProductRepo;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function () {          
            $this->autoRecived();
            $this->groupbuyStop();
            $this->autoCancle();
            $this->autoDown();
            $this->autoUp();
        })->everyFiveMinutes();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }

    
    

    /**
     * 拼团过期
     */
    private function groupbuyStop()
    {        
        OrderGroupRepo::groupFaild();            
    }


    //订单发货后7天自动变成已收货
    private function autoRecived()
    {
        OrderRepo::autoRecived();
    }

    // 未支付自动取消
    private function autoCancle()
    {
        OrderRepo::autoCancle();
    }

    // 商品过了有效期自动下架
    private function autoDown()
    {
        ProductRepo::autoDown();
    }

    private function autoUp()
    {
        ProductRepo::autoUp();
    }

    
}
